<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" isELIgnored="false" %>
<!doctype html>
<html>

<head>
  <meta charset="utf-8"/>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>会员登录</title>

  <!-- 引入自定义css文件 style.css -->

  <link rel="stylesheet" href="${pageContext.request.contextPath}/css/style.css" type="text/css"/>
  <script src="${pageContext.request.contextPath}/js/jquery-2.1.4.min.js"
          type="text/javascript"></script>
  <script src="${pageContext.request.contextPath}/js/bootstrap-3.1.1.min.js"
          type="text/javascript"></script>

  <style>
    body {
      margin-top: 20px;
      margin: 0 auto;
    }

    .carousel-inner .item img {
      width: 100%;
      height: 300px;
    }
  </style>
</head>

<body>

<jsp:include page="head.jsp"/>
<div class="container">
  <div class="row">
    <div style="margin:0 auto; margin-top:10px;width:1150px;">
      <strong>我的订单</strong>
      <%-- <a href="${pageContext.request.contextPath}/order/orderDeleteAll.do">[清空订单]</a>--%>
      <table class="table table-bordered">
        <c:forEach items="${page.list}" var="order">
          <tbody>
          <tr class="success">
            <c:if test="${order.state == 1}">
              <th colspan="4">
                订单编号:${order.oid}
              </th>
              <th style="text-align: right">
                <c:if test="${order.state == 2 || order.state == 3}">
                  <a href="${pageContext.request.contextPath}/order/expcheck.do?oid=${order.oid}">快递查询</a>
                </c:if>
              </th>
            </c:if>
            <c:if test="${order.state != 1}">
              <th colspan="5">
                订单编号:${order.oid}
              </th>
            </c:if>
          </tr>
          <tr class="warning">
            <th>图片</th>
            <th>商品</th>
            <th>价格</th>
            <th>数量</th>
            <th>小计</th>
          </tr>
          <c:forEach items="${order.orderitems}" var="item">
            <tr class="active">
              <td width="17%">
                <input type="hidden" name="id" value="22">
                <a target="_blank"
                   href="${pageContext.request.contextPath}/order/orderPay.do?oid=${order.oid}">
                  <img src="${pageContext.request.contextPath}/${item.product.image}"
                       width="70" height="60">
                </a>
              </td>
              <td width="30%">

                <a target="_blank"
                   href="${pageContext.request.contextPath}/order/orderPay.do?oid=${order.oid}">${item.product.name}</a>
              </td>
              <td width="20%">
                ￥${item.product.shopPrice}
              </td>
              <td width="10%">
                  ${item.count}
              </td>
              <td width="18%">
                <span class="subtotal">￥${item.subtotal}</span>
              </td>
            </tr>
          </c:forEach>
            <%--要记一下--%>
          <tr class="success">
            <th>
              <c:if test="${order.state != 0 && order.state != 4 }">
                <%--<a href="/order/orderCancel.do?oid=${order.oid}">退款</a>--%>
              <a href="javascript:;" data-toggle="modal" data-target="#myModal-${order.oid}">
                退款
              </a>
                <%--modal--%>
              <div class="modal fade" id="myModal-${order.oid}" tabindex="-1" role="dialog"
                   aria-labelledby="myModalLabel">
                <div class="modal-dialog" role="document">
                  <div class="modal-content">
                    <div class="modal-header">
                      <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span></button>
                      <h4 class="modal-title" id="myModalLabel">退款请求</h4>
                    </div>
                    <div class="modal-body">

                      <div id="body3" class="tab-content" name="divcontent">
                        <input id="WIDTRout_trade_no" name="WIDTRout_trade_no"
                               value="${order.oid}" type="hidden"/><%--订单号--%>
                          <%--<input id="WIDTRtrade_no" name="WIDTRtrade_no" value="" type="hidden"/>交易号--%>
                        <input id="WIDTRrefund_amount" name="WIDTRrefund_amount"
                               value="${order.total}" type="hidden"><%--订单价格--%>
                        <input id="WIDTRout_request_no" name="WIDTRout_request_no"
                               type="hidden"/><%--退款请求号--%>
                          <%----%>
                        <div class="form-group">
                          <label for="refund_amount">您的退款金额</label>
                          <input readonly="readonly" type="text" class="form-control"
                                 id="refund_amount" value="${order.total}">
                        </div>
                        <div class="form-group">
                          <span>退款原因</span>
                          <div id="ddlRegType">
                            <select>
                              <option ng-repeat="x in names">正常退款</option>
                              <option ng-repeat="x in names">拍错了</option>
                              <option ng-repeat="x in names">长时间未发货</option>
                              <option ng-repeat="x in names">不想要了</option>
                            </select>
                          </div>
                        </div>

                        <div class="modal-footer">
                          <button type="button" class="btn btn-default" data-dismiss="modal">
                            Close
                          </button>
                          <button type="button" onclick="refund()" id="ordercancel"
                                  class="btn btn-primary ">
                            退款
                          </button>
                        </div>
                      </div>
                    </div>
                  </div>
                  </c:if>
                  <c:if test="${order.state == 0 || order.state == 4}">
                  <a href="javascript:;" onclick="del('${order.oid}')">删除订单</a>
                  </c:if>
            </th>
            <th colspan="2"></th>
            <th>订单总价</th>
            <th>￥${order.total}
              <c:if test="${order.state == 0}">
                <a href="${pageContext.request.contextPath}/order/orderPay.do?oid=${order.oid}">付款</a>
              </c:if>
              <c:if test="${order.state == 1}">
                <span style="color: red">订单已付款</span>
                <a href="${pageContext.request.contextPath}/order/confirm.do?oid=${order.oid}">确认收货</a>
              </c:if>
              <c:if test="${order.state == 3}">
                <span style="color: red">订单已收货</span>
              </c:if>
              <c:if test="${order.state == 2}">
                <span style="color: red">订单已发货</span>
                <a href="${pageContext.request.contextPath}/order/confirm.do?oid=${order.oid}">确认收货</a>
              </c:if>
              <c:if test="${order.state == 4}">
                <span style="color: red">订单已退款</span>
              </c:if>
            </th>
          </tr>
          <tr>
            <th colspan="5" height="5px"></th>
          </tr>
          </tbody>
        </c:forEach>
      </table>
    </div>
    <c:if test="${page.size == 0}">
      <h1>亲， 并没有订单哦</h1>
    </c:if>
  </div>

  <!--分页 -->
  <div style="width:380px;margin:0 auto;margin-top:50px;text-align: center">
    <ul class="pagination" style="text-align:center; margin-top:10px;">
      <li>
        <a href="${pageContext.request.contextPath}/order/orderlist.do?pageid=${page.prePage}"
           aria-label="Previous">
          <span aria-hidden="true">&laquo;&laquo;</span></a>
      </li>

      <c:forEach begin="${page.navigateFirstPage}" end="${page.navigateLastPage}"
                 var="i">
        <c:if test="${page.page != i}">
          <li>
            <a href="${pageContext.request.contextPath}/order/orderlist.do?pageid=${i}">${i}</a>
          </li>
        </c:if>
        <c:if test="${page.page == i}">
          <li class="active">
            <a href="${pageContext.request.contextPath}/order/orderlist.do?pageid=${i}">${i}</a>
          </li>
        </c:if>
      </c:forEach>
      <li>
        <a href="${pageContext.request.contextPath}/order/orderlist.do?pageid=${page.nextPage}"
           aria-label="Next">
          <span aria-hidden="true">&raquo;&raquo;</span>
        </a>
      </li>

    </ul>
  </div>
  <!-- 分页结束=======================        -->
</div>

<jsp:include page="foot.jsp"/>
</body>
<script>

  var time = 1;

  function del(ev) {
    if (confirm("确定删除了吗？")) {
      $.post(
          "${pageContext.request.contextPath}/order/orderDelete.do",
          "oid=" + ev,
          function (d) {

            var windowWidth = $(window).width();
            var tipsDiv = '<div class="tipsClass" style="font-size: 24px">正在删除</div>';

            $('body').append(tipsDiv);
            $('div.tipsClass').css({
              'top': 100 + 'px',
              'left': ( windowWidth / 2 ) - 350 / 2 + 'px',
              'position': 'absolute',
              'padding': '20px 40px',
              'background': '#8FBC8F',
              'font-size': 26 + 'px',
              'margin': '10px auto',
              'text-align': 'center',
              'width': '350px',
              'height': 'auto',
              'color': '#fff',
              'opacity': '0.8'
            }).show();
            setTimeout(function () {
              $('div.tipsClass').fadeOut();
            }, (0.5 * 1000));

            if (d.msc == 1) {
              window.setInterval(function () {
                time--;
                if (time == 0) {
                  location.href = "${pageContext.request.contextPath}/order/orderlist.do";
                }
              }, 1000);
            }
          }
      )
    }
  }

  function refund() {
    var refund_reason = $("#ddlRegType").find("option:selected").val();
    var refund_amount = $("#refund_amount").val();
    var WIDTRout_trade_no = $("#WIDTRout_trade_no").val();

    location.href = "${pageContext.request.contextPath}/order/orderCancel.do?WIDTRout_trade_no="
        + WIDTRout_trade_no
        + "&WIDTRrefund_amount=" + refund_amount + "&WIDTRrefund_reason=" + refund_reason;

  }

</script>
</html>